home *** CD-ROM | disk | FTP | other *** search
Wrap
;############################################################################## ;# ;# Add or update syntax higlighting for AutoHotKey scripts in UltraEdit ;# ;# Mod of a script done by Tekl (although not much has survived) ;# Mod done by toralf, 2005-02-15 ;# ;# Tested with: AHK 1.0.26.00, Windows XP Pro, UltraEdit 10.10c/10.20 ;# ;# Requirements ;# - Syntax files for AHK in one directory ;# - UltraEdit uses standard file for highlighting => wordfile.txt ;# ;# Customize: ;# - The default color for strings is gray, change it to any color ;# you want to have "%var%" to appeer => Extra->Option->syntaxhiglighting ;# - Change the default color for up to 8 keyword groups ;# => Extra->Option->syntaxhiglighting ;# -specify up to 8 syntax files, each containing one keywords per line ;# => you can add your own files, for keywords that you want to highlight ;# Personally I use 3 additional: Operators, Separators and Special ;# Operators.txt => "=`n<`n>`n*`n/`n+`n-" ;# Separators.txt => "``n`n``r`n|`n,`n{`n}" ;# Special.txt => "** x y w h r v g`nis`nnot`nCBlue`ncRed" ;# ; Specify a list of up to 8 syntax files; the order influences the color given to them by UE by default SyntaxFileNameList = CommandNames|Keywords|Variables|Keys ; e.g. add |Operators|Separators|Special ;Default colors in UE: blue |red |orange |green |brown |blue |blue |blue SyntaxExtention = .txt ;############# END of Customization Area ################################## ;############# Ask and Check for valid input ############################### RegRead, UeditPath, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\UEDIT32.exe,Path IfNotExist, %UeditPath%\uedit32.exe { UeditPath = %A_ProgramFiles%\UltraEdit IfNotExist, %UeditPath%\uedit32.exe { FileSelectFolder, UeditPath,, 0, Select UltraEdit program-folder IfNotExist, %UeditPath%\uedit32.exe { MsgBox UltraEdit cannot be found. ExitApp } } } UEini = %APPDATA%\IDMComp\UltraEdit\uedit32.ini IfNotExist, %UEini% { UEini = %A_WinDir%\uedit32.ini IfNotExist, %UEini% FileSelectFile, UEini, 1, %A_ProgramFiles%\UltraEdit, Select UltraEdit INI-File, *.ini } IniRead, UEwordfile, %UEini%, Settings, Language File if UEwordfile = ERROR { MsgBox INI-File "%UEini%" is missing the Key "Language File". ExitApp } ;Search or ask for Wordfile, when it doesn't exist -> exit UEwordfile = %UeditPath%\wordfile.txt IfNotExist, %UEwordfile% { FileSelectFile, UEwordfile, 1, %A_ProgramFiles%, Select UltraEdit wordfile, *.txt IfNotExist, %UEwordfile% { MsgBox UltraEdit Wordfile cannot be found. ExitApp } } ; Search or ask for specified syntax folder and files, when they don't exist -> exit ; Get path of AHK Installation so that syntax files can be found more reliably: RegRead, ahkpath, HKEY_LOCAL_MACHINE, SOFTWARE\AutoHotKey, InstallDir PathSyntaxFiles = %ahkpath%\AutoHotkey\Extras\Editors\Syntax IfNotExist, %PathSyntaxFiles% { PathSyntaxFiles = %A_ProgramFiles%\AutoHotkey\Extras\Editors\Syntax IfNotExist, %PathSyntaxFiles% { FileSelectFolder, PathSyntaxFiles, %A_ProgramFiles%,2, Select Folder "AutoHotkey\Extras\Editors\Syntax" IfNotExist, %PathSyntaxFiles% { MsgBox Folder containing syntax files not found. ExitApp } } } MissingFile = FileCount = 0 Loop, Parse, SyntaxFileNameList, | { FileCount += 1 IfNotExist, %PathSyntaxFiles%\%A_LoopField%%SyntaxExtention% MissingFile = %MissingFile%`n%A_LoopField%%SyntaxExtention% } If MissingFile is not space { MsgBox AHK Syntax file(s)`n%MissingFile%`n`ncannot be found in`n`n%PathSyntaxFiles%\. ExitApp } If FileCount > 8 { MsgBox You have specified %FileCount% Syntax files.`nOnly 8 are supported be UltraEdit.`nPlease shorten the list. ExitApp } ;Check the number of languages in the current wordfile, if more than 19 without AHK -> exit NumberOfLanguages = 0 Loop, Read, %UEwordfile% { StringLeft, WFdef, A_LoopReadLine, 2 if WFdef = /L { StringSplit, WFname, A_LoopReadLine, " LanguageName = %WFname2% if LanguageName <> AutoHotkey NumberOfLanguages += 1 } } If NumberOfLanguages > 19 { MsgBox, 48,, The wordfile has %NumberOfLanguages% syntax-schemes. UltraEdit does only support 20 schemes.`nPlease delete schemes from the file! ExitApp } ;############# Read keywords from syntax files into arrays ################ Loop, Parse, SyntaxFileNameList, | ;Read all syntax files { SyntaxFileName = %A_LoopField% GoSub, ReadSyntaxFromFile ;SyntaxFileName will become string with keywords } ;############# Build language specific highlight for AHK ################## StrgAHKwf = "AutoHotkey" Nocase StrgAHKwf = %StrgAHKwf% Line Comment = `; StrgAHKwf = %StrgAHKwf% Line Comment Preceding Chars = [~``] ;to escape escaped ; StrgAHKwf = %StrgAHKwf% Escape Char = `` StrgAHKwf = %StrgAHKwf% String Chars = `% StrgAHKwf = %StrgAHKwf% Block Comment On = /* StrgAHKwf = %StrgAHKwf% Block Comment Off = */ StrgAHKwf = %StrgAHKwf% File Extensions = ahk`n StrgAHKwf = %StrgAHKwf%/Delimiters = *~`%+-!^&(){}=|\/:"'``;<>%A_Tab%,%A_Space%.`n StrgAHKwf = %StrgAHKwf%/Indent Strings = "{" ":"`n StrgAHKwf = %StrgAHKwf%/Unindent Strings = "}" "Return" "Else"`n StrgAHKwf = %StrgAHKwf%/Function String = "`%^([a-zA-Z0-9#_@$?^[^]]+^):"`n StrgAHKwf = %StrgAHKwf%/Function String 1 = "`%^([~; ^t^p]*^)`::"`n Loop, Parse, SyntaxFileNameList, | ;Add the keywords from syntax strings into their sections { StrgAHKwf = %StrgAHKwf%/C%A_Index%"%A_LoopField%" ;section definition SyntaxString = %A_LoopField% ;which section/syntax GoSub, ParseSyntaxString ;parse through string and add to list } ;############# Add or Update Wordfile ##################################### ;Name of a file for temporary store the word file TemporaryUEwordFile = TempUEwordFile.txt FileDelete, %TemporaryUEwordFile% Loop, Read, %UEwordfile%, %TemporaryUEwordFile% ;Read through Wordfile { StringLeft, WFdef, A_LoopReadLine, 2 if WFdef = /L { StringSplit, WFname, A_LoopReadLine, " LanguageName = %WFname2% LanguageNumber = %WFname1% StringTrimLeft,LanguageNumber,LanguageNumber,2 if LanguageName = AutoHotkey ;when AHK section found, place new section at same location { FileAppend, /L%LanguageNumber%%StrgAHKwf% AHKLanguageFound := True } } if LanguageName <> AutoHotkey ;everything that does not belong to AHK, gets unchanged to file FileAppend, %A_LoopReadLine%`n } if not AHKLanguageFound ;when AHK section not found, append AHK section { LanguageNumber += 1 FileAppend, /L%LanguageNumber%%StrgAHKwf%, %TemporaryUEwordFile% } FileCopy, %UEwordfile%, %UEwordfile%.ahk.bak, 1 ;Create Backup of current wordfile FileMove, %TemporaryUEwordFile%, %UEwordfile%, 1 ;Replace wordfile with temporary file ; Tell user what has been done Question = `n`nWould you like to make UltraEdit the default editor for AutoHotkey scripts (.ahk files)? if AHKLanguageFound MsgBox, 4,, The AutoHotkey-Syntax for UltraEdit has been updated in your wordfile:`n`n%UEwordfile%`n`nA backup has been created in the same folder.%Question% else MsgBox, 4,, The AutoHotkey-Syntax for UltraEdit has been added to your wordfile:`n`n%UEwordfile%`n`nA backup has been created in the same folder.%Question% IfMsgBox, Yes RegWrite, REG_SZ, HKEY_CLASSES_ROOT, AutoHotkeyScript\Shell\Edit\Command,, %UeditPath%\uedit32.exe "`%1" ExitApp ; That's it, exit ;############# SubRoutines ################################################ ReadSyntaxFromFile: TempString = Loop, Read , %PathSyntaxFiles%\%SyntaxFileName%%SyntaxExtention% ;read syntax file { StringLeft,Char, A_LoopReadLine ,1 ;if line is comment, don't bother, otherwise add keyword to string If Char <> `; { ;only add first word in line Loop parse, A_LoopReadLine, `,%A_Tab%%A_Space% { TempString = %TempString%%A_LoopField%`n break } } } %SyntaxFileName% = %TempString% ;Assign string to syntax filename Sort, %SyntaxFileName%, U ;Sort keywords in string return ParseSyntaxString: Loop, Parse, %SyntaxString%, `n ;parse through syntax string { StringLeft, Char, A_LoopField,1 If (Char = PrevChar) ;add keyword to line when first character is same with previous keyword StrgAHKwf = %StrgAHKwf% %A_LoopField% else ;for every keyword with a new first letter, start a new row StrgAHKwf = %StrgAHKwf%`n%A_LoopField% PrevChar = %Char% ;remember first character of keyword } return ;############# END of File ################################################